#include "KeeperBasic.h"

std::string usToString(uint64_t us) {
  std::stringstream ss;
  if (us < 1000) {
    // us
    ss << std::fixed << std::setprecision(0) << us << " us";
  } else if (us < 1000000) {
    // ms
    double tmp = static_cast<double>(us / 1000.0);
    ss << std::fixed << std::setprecision(1) << tmp << " ms";
  } else if (us < (uint64_t)600 * 1000000) {
    // second: 1 s -- 600 s (10 mins)
    double tmp = static_cast<double>(us / 1000000.0);
    ss << std::fixed << std::setprecision(1) << tmp << " s";
  } else {
    // minute
    double tmp = static_cast<double>(us / 60.0 / 1000000.0);
    ss << std::fixed << std::setprecision(0) << tmp << " m";
  }
  return ss.str();
}
